package xin.marcher.module.common.enums.message;

import java.util.HashMap;
import java.util.Map;

/**
 * 消息类型枚举
 */
public enum MessageTypeEnum {

    /**
     * 内部消息
     */
    INTERNAL_MESSAGE(1, "内部消息"),

    /**
     * 外部消息
     */
    EXTERNAL_MESSAGE(2, "外部消息");

    private Integer code;

    private String value;

    MessageTypeEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static Map<Integer, String> toMap() {
        Map<Integer, String> map = new HashMap<>(16);
        for (MessageTypeEnum element : MessageTypeEnum.values()) {
            map.put(element.getCode(), element.getValue());
        }
        return map;
    }

    public static MessageTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (MessageTypeEnum element : MessageTypeEnum.values()) {
            if (code.equals(element.getCode())) {
                return element;
            }
        }
        return null;
    }
}
